package org.chen.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.chen.dto.TtsLanguageDTO;
import org.chen.entity.TtsLanguage;
import org.chen.mapper.TtsLanguageMapper;
import org.chen.service.TtsLanguageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class TtsLanguageServiceImpl extends ServiceImpl<TtsLanguageMapper, TtsLanguage> implements TtsLanguageService {

    @Autowired
    private TtsLanguageMapper languageMapper;

    @Override
    public List<TtsLanguageDTO> getAllLanguages() {
        List<TtsLanguage> languages = languageMapper.selectList(null);
        return languages.stream().map(this::convertToDTO).collect(Collectors.toList());
    }

    private TtsLanguageDTO convertToDTO(TtsLanguage language) {
        TtsLanguageDTO dto = new TtsLanguageDTO();
        dto.setCode(language.getLanguageCode());
        dto.setName(language.getName());
        return dto;
    }
}